home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12532 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: ix.netcom.com!news
  2. From: ishky@ix.netcom.com(Andrew Heiz )
  3. Newsgroups: comp.lang.c
  4. Subject: Why does my program do this?
  5. Date: 1 Apr 1996 04:22:58 GMT
  6. Organization: Netcom
  7. Message-ID: <4jnln2$95j@dfw-ixnews3.ix.netcom.com>
  8. NNTP-Posting-Host: ix-li2-16.ix.netcom.com
  9. X-NETCOM-Date: Sun Mar 31 10:22:58 PM CST 1996
  10.  
  11. Hi again,
  12.  
  13. There have been so many helpful readers out there here is another
  14. question for you.
  15.  
  16. I've declared an 2 dimentional array:
  17.  
  18. char scores[STUDENT][5];
  19.  
  20. I am entering the scores in 2 for loops like this:
  21.  
  22.     for (i=0; i <= students-1; i=i+1)
  23.         {
  24.             for (j=0; j <= tests-1; j=j+1)
  25.             {
  26.                 gets(&scores[i][j];
  27.             }
  28.         }
  29.  
  30. I print out the scores in the same type of loop structure:
  31.  
  32.     for (i=0; i <= students-1; i=i+1)
  33.         {
  34.         printf("Scores for student %d",i+1);
  35.             for (j=0; j <= tests-1; j=j+1)
  36.             {
  37.                 printf("\tGrade %d: %s",j+1,scores[i][j]);
  38.             }
  39.         }
  40.  
  41. I am getting (if you don't already know this):
  42.  
  43.         Scores for student 1: Grade 1: 999991   Grade 2: 99991   Grade
  44. 3: 9991    Grade 4: 991    Grade 5: 91
  45.  
  46. Is my data being mangled some how in the data entry? I've tried just
  47. printing out 1 array element or not using the loop and naming each
  48. element but nothing seems to work.
  49.  
  50. If you can explain why this is happening and how to fix it my computer
  51. would be greatful. I've been making some awful threats at it today. It
  52. must be something simple I'm overlooking.
  53.  
  54. Thanks again if you have helped me in the past and with this question.
  55.  
  56. Please post or e-mail your response.
  57.  
  58. Happy coding,
  59. Andy
  60. e-mail ishky@ix.netcom.com
  61.